package main

import (
	"fmt"
	"math"
	"math/big"
)

func main() {
	// calculation with bigInts
	intM := big.NewInt(math.MaxInt64)
	intN := intM
	intO := big.NewInt(1987)
	intP := big.NewInt(2)
	intP.Mul(intM, intN)
	fmt.Printf("The Big Int intP is %v\n", intP)
	intP.Add(intP, intM).Div(intP, intO)
	fmt.Printf("The Big Int intP is %v\n", intP)

	int1 := big.NewInt(1)
	int2 := big.NewInt(2)
	int1.Mul(big.NewInt(3), big.NewInt(4))
	fmt.Printf("The Big Int int1 is %v\n", int1)
	int1.Add(int1, big.NewInt(6)).Div(int1, int2).Sub(big.NewInt(5), int1)
	// ==> int1 = int1 + 6; int1 = int1 / 2; int1 = 5 - int1; output: -4
	fmt.Printf("The Big Int int1 is %v\n", int1)

	ratM := big.NewRat(math.MaxInt64, 1987)
	ratN := big.NewRat(-1987, math.MaxInt64)
	ratO := big.NewRat(19, 56)
	ratP := big.NewRat(123, 246)
	ratQ := big.NewRat(1, 1)
	ratQ.Mul(ratM, ratN).Add(ratQ, ratO).Mul(ratQ, ratP)
	// ratQ = ratM * ratN + ratO; ratQ = ratQ * ratP
	// maxInt/1987 * (-1987/maxInt) + 19/56 = -37/56; -37/56 * 123/246 = -37/112
	fmt.Printf("ratQ is %v\n", ratQ)
	// output: ratQ is -37/112

}
